﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WC.DL.DALC.Factory;
using WC.BL.BE;

namespace WC.BL.BCC
{
    public class PopUpBC
    {
        public static string update(PopUPBE objPopUp)
        {
            string retval = string.Empty;
            try
            {
                retval = DAOFactory.PopUpDALC.update(objPopUp);
            }
            catch (Exception ex)
            {
                retval = ex.Message;
            }
            return retval;
        }

        public static string write(PopUPBE objPopUp)
        {
            string retval = string.Empty;
            try
            {
                //-- Registrar popup para todos los ramos:
                List<GenericBE> lstRamos;
                if (string.IsNullOrEmpty(objPopUp.Ramo_id))
                {
                    lstRamos = DAOFactory.SectorDALC.list(string.Empty, string.Empty);
                    foreach (GenericBE obj in lstRamos)
                    {
                        if (string.IsNullOrEmpty(obj.Codigo)) { continue; }
                        objPopUp.Ramo_id = obj.Codigo;
                        retval = DAOFactory.PopUpDALC.write(objPopUp);
                    }
                }
                else
                {
                    retval = DAOFactory.PopUpDALC.write(objPopUp);
                }
            }
            catch (Exception ex)
            {
                retval = ex.Message;
            }
            return retval;
        }

        public static PopUPBE read(int id){
            PopUPBE retval = null;
            try
            {
                retval = DAOFactory.PopUpDALC.read(id);
            }
            catch { }
            return retval;
        }
        public static List<PopUPBE> read(PopUPBE pObjPopUPBE) {
            List<PopUPBE> retval = null;
            try
            {
                retval = DAOFactory.PopUpDALC.read(pObjPopUPBE);
            }
            catch (Exception ex)
            {
                retval = null;
            }
            return retval;
        }
        public static string popupsXramo(string id)
        {
            
            string html = string.Empty;
            string cuerpo = string.Empty;
            List<PopUPBE> lstm = DAOFactory.PopUpDALC.popupsXramo(id);
            if (lstm != null)
            {
                if (lstm.Count > 0)
                {
                    // genero la pagia popup
                    html = "<html>" +
                    "<head>  </head> " +
                    "<body> <div class=" + (char)34 + "modalPopupBody" + (char)34 + "> " +
                    "<table style=" + (char)34 + "width: 45%;" + (char)34 + ">";
                    foreach (PopUPBE m in lstm)
                    {
                        cuerpo += "<tr> <td> <b>" + m.Titulo + "</b> " +
                                            " <br /> " +
                                     " </td> " +
                                 "</tr> " +
                                 " <tr> " +
                                        "<td>" +
                                                 "<img src=" + (char)34 + ParametroBC.Instance.getParamValue("RutaImgPopUp") + m.Imagen + (char)34 + 
                                                 "style="+  (char)34 + "height: 180px; width: 221px"+ (char)34 + " />" +
                                        "</td>" +
                                 " </tr>" +
                                 //" <tr> " +
                                 //       "<td>" +
                                 //           "Fecha Inicio: " + DateTime.Parse(m.Fechai).ToShortDateString() +
                                 //      "&nbsp;&nbsp;&nbsp;&nbsp;" +
                                 //           "Fecha Fin: " + DateTime.Parse(m.Fechaf).ToShortDateString() +
                                 //       "</td>" +
                                 //" </tr>" +
                                 " <tr> " +
                                        "<td>" +
                                            "<hr style=" + (char)34 + "width: 590px" + (char)34 + " />" +
                                        "</td>" +
                                 " </tr>";
                    }
                    html = html + cuerpo + "</table> </div> </body> </html>";
                }
            }

            return html;
        
        }
        public static string delete(int pIdPopUp) 
        {
            string retval = null;
            try
            {
                retval = DAOFactory.PopUpDALC.delete(pIdPopUp);
            }
            catch (Exception ex)
            {
                retval = null;
            }
            return retval;   
        }

        public static int numeropopusXramo(string id)
        {
            List<PopUPBE> lstm = DAOFactory.PopUpDALC.popupsXramo(id);
            return lstm.Count();
        }
    }

}
